package com.xinfu.newproject.presenter;

import com.xinfu.newproject.bean.matter_repair.AddRepairBean;
import com.xinfu.newproject.bean.matter_repair.AddRepairBody;
import com.xinfu.newproject.bean.matter_repair.bean.RepairEvaluateBean;
import com.xinfu.newproject.bean.matter_repair.body.RepairEvaluateBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.matter_repair.AddRepairModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class AddRepairPresenter {
    private IView.ISubmitRepairView mISubmitRepairView;

    private AddRepairModel mAddRepairModel;

    public AddRepairPresenter(IView.ISubmitRepairView iSubmitRepairView) {
        this.mISubmitRepairView = iSubmitRepairView;
        mAddRepairModel = new AddRepairModel();
    }

    /**
     * 提交报修
     */
    public void submitRepair() {

        AddRepairBody addRepairBody = new AddRepairBody(mISubmitRepairView.header(),
                mISubmitRepairView.userId(),
                mISubmitRepairView.contents(),
                mISubmitRepairView.userName(),
                mISubmitRepairView.mobile(),
                mISubmitRepairView.repairDate(),
                mISubmitRepairView.attachFile(),
                mISubmitRepairView.repairPartId(),
                mISubmitRepairView.repairWay(),
                mISubmitRepairView.bespeakFromTime(),
                mISubmitRepairView.bespeakToTime(),
                mISubmitRepairView.tenantId(),
                mISubmitRepairView.projectId(),
                mISubmitRepairView.roomId(),
                mISubmitRepairView.repairArea());

        mAddRepairModel.submitRepair(addRepairBody, new MyCallBack<AddRepairBean>() {
            @Override
            public void onSuccess(AddRepairBean addRepairBean) {

                if (addRepairBean.isSuccess()) {
                    mISubmitRepairView.getData(addRepairBean);
                } else {
                    mISubmitRepairView.showToast(addRepairBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {

                mISubmitRepairView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mISubmitRepairView.closeDispose(disposable);
            }
        });


    }


    /**
     * 报修评价
     */
    public void repairEvaluate() {

        RepairEvaluateBody repairEvaluateBody = new RepairEvaluateBody(mISubmitRepairView.header(), mISubmitRepairView.repairId(), mISubmitRepairView.reviewContent(),mISubmitRepairView.attachFile(),mISubmitRepairView.repairWay(),mISubmitRepairView.userName());

        mAddRepairModel.repairEvaluate(repairEvaluateBody, new MyCallBack<RepairEvaluateBean>() {
            @Override
            public void onSuccess(RepairEvaluateBean repairEvaluateBean) {

                if (repairEvaluateBean.isSuccess()) {
                    mISubmitRepairView.getData(repairEvaluateBean);
                } else {
                    mISubmitRepairView.showToast(repairEvaluateBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {

                mISubmitRepairView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mISubmitRepairView.closeDispose(disposable);
            }
        });


    }

}
